<? require("../header.inc"); ?>
<? require("../db.php"); ?>


<?
$TableName = $_GET['TableName'];
if ($TableName == "") $TableName = $_POST['TableName'];
if ($TableName == "") $TableName = "MainSupportTree";
$FromNode = $_GET['FromNode'];
if ($FromNode == "") $FromNode = $_POST['FromNode'];
if ($FromNode == "") $FromNode = 1;  
$Link = "";
$dbOpenDynaset = 2;
$db = connectdb();

$SQLQ = "SELECT * FROM SupportCategories ORDER BY CategoryID;";
$rinfo = mysql_query($SQLQ);
if (!($rinfo))
{
echo "RInfo Failure: $SQLQ" ;
die();
}

$AddToNode = $_POST["Descr"];
if ($AddToNode != "") 
{
	
	//'Add the item to the correct tree node !
	//TheTable.Close
	//Set TheTable = CurrentDB.OpenRecordset (TableName)

	$CatList = $_POST["Categories"];
	$V = substr (1,CatList,",");

	$LinkFile = "null";
	$Descr = "null";
	$URLLink = "null";
	$GotoMenu = "null";
	$Keywords = "null";
	$notes = "null";
	$OrderID = 99;
	if ($_POST['Descr'] != "") $Descr = $_POST['Descr'];
	if ($_POST['LinkFile'] != "") $LinkFile = $_POST['URLLink'];
	if ($_POST['GotoMenu'] != "") $GotoMenu = $_POST['GotoMenu'];
	if ($_POST['Keywords'] != "") $Keywords = $_POST['Keywords'];
	if ($_POST['Notes'] != "") $notes = $_POST['Notes'];
	else
	{
	echo "Notes is null !";
	die();
	}

	if ($V != 0) 
		{
		$MyArray = explode($CatList,",");
		$len = len($MyArray);


		for ($I=0;$I<$len;$I++)
			{
	
			$BelongsTo = $MyArray[$I];			
			$INSERTSTR = "INSERT INTO $TableName (Description,LinkFile,GotoTree,Keywords,Notes,BelongsTo,OrderID) VALUES ('$Descr','$LinkFile','$GotoMenu','$Keywords','$Notes','$BelongsTo','$OrderID')";
			$result = mysql_query($INSERTSTR);
		if (!($result)) 
			 { echo "Sorry, there was an error adding this item. Str was: $INSERTSTR";die(); }
			else
			{
			header ("Location:/troubleshooter/troubleshooter.php");
			die();
			}


			}
		}

	else
		{

		$BelongsTo = $CatList;
		$INSERTSTR = "INSERT INTO $TableName (Description,LinkFile,GotoTree,Keywords,Notes,BelongsTo,OrderID) VALUES ('$Descr','$LinkFile','$GotoMenu','$Keywords','$Notes','$BelongsTo','$OrderID')";
		$result = mysql_query($INSERTSTR);
		if (!($result)) 
		{ echo "Sorry, there was an error adding this item. Str was: $INSERTSTR";die(); }

		else
		{
		header ("Location:/troubleshooter/troubleshooter.php");
		die();
		}



		}

}
else 
{

?>

<HTML>
<HEAD>
<SCRIPT Language="Javascript">
function updateitem ()
{
alert ("Note: You cannot link to a file AND choose to goto a new category !");
MyForm.URLLink.value = "";
//MyForm.URLLink.value = "{MENUITEM: " + MyForm.GotoMenu.value + "}";
}
</SCRIPT>
<STYLE TYPE="text/css">

body	{filter: progid:DXImageTransform.Microsoft.gradient(enabled='true',
                startColorstr=#00FFFFFF, endColorstr=#FFE0DFE3); height:100%; width:100%;

}

H1	{
	font: normal 175% Trebuchet MS;
	margin-top: 1em;
	margin-left: 30px;
	margin-bottom: -.7em;
	color: #9999CC;
}

p.welcome	{
			font: 105% Verdana;
		 	color: #666699;
		 	margin-left: 3em;
			margin-top: 1em;
			margin-right: 4em;
}
</STYLE>

</HEAD>
<BODY>
<P>Add Link to Support Tree: <? echo $TableName ?>  </P>
<HR>

<FORM Name=MyForm ACTION="tsadditem.php" METHOD="POST">
<TABLE>
<TD>&nbsp;</TD> <TD> <A HREF="tsmakecat.php?TableName=<? echo $TableName . "&FromNode=" . $FromNode; ?>"> Add Category </A>  </TD><TR>
<TD>Add to Categories: </TD> 
<TD> 

<SELECT MULTIPLE SIZE=5 NAME="Categories">
<?
$OptionList = "";

$FromNode = $_GET['FromNode'];
if ($FromNode == "") $FromNode = $_POST['FromNode'];
if ($FromNode == "") $FromNode = 1;  


while ($myrow = mysql_fetch_array($rinfo))
{
//echo "F: $FromNode C: " . $myrow["CategoryID"];
if ($FromNode == $myrow["CategoryID"])
$OptionList = $OptionList .  "\n<OPTION SELECTED Value='" . $myrow["CategoryID"] . "'>" . $myrow["CategoryName"] . "</OPTION>";
else
$OptionList = $OptionList . "\n<OPTION Value='" . $myrow["CategoryID"] . "'>" . $myrow["CategoryName"] .  "</OPTION>";

}


echo $OptionList;
?>

</SELECT>

</TD>

<TR>
<TD>Description: </TD> <TD> <INPUT TYPE="textbox" size=50 name="Descr"></TD>
<TR>
<TD>Goto Menu: </TD> <TD> <SELECT Name="GotoMenu" OnChange='updateitem();' ><OPTION Value="0" SELECTED>None</OPTION>
<? echo $OptionList; ?> 
</SELECT></TD>
<TR>

<TR>
<TD>Link To: </TD> <TD> <INPUT TYPE="textbox" size=50 name="URLLink"></TD>
<TR>
<TD>Keywords: </TD> <TD> <INPUT TYPE="textbox" size=50 name="keywords"></TD>
<TR>
<TD>Notes: </TD><TD>(will appear in left hand pane)</TD> <TR>
<TD>&nbsp;</TD>
<TD> <textarea name="Notes" rows="5" cols="35" wrap="physical" Value="notes"></textarea></TD>

</TABLE>
<CENTER>
<INPUT Type="hidden" name="FromNode" value="<? echo $FromNode; ?>">
<INPUT Type="hidden" name="TableName" value="<? echo $TableName; ?>">
<INPUT Type="submit" name="submit" value = "Add Item">
</CENTER>
</FORM>
<FONT FACE = "Arial">
<P>
</FONT>
<? }?>

</BODY>
</HTML>
